//
//  PhotoViewController.m
//  照相机demo
//
//  Created by Jason on 11/1/16.
//  Copyright © 2016年 Jason. All rights reserved.
//

#import "PhotoViewController.h"
#import "UIButton+DJBlock.h"
#define AppWidth [[UIScreen mainScreen] bounds].size.width//

#define AppHeigt [[UIScreen mainScreen] bounds].size.height
@interface PhotoViewController ()

@end

@implementation PhotoViewController
-(void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
   
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"照片";
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 40, 40);
    [button setTitle:@"确定" forState:UIControlStateNormal];
    button.titleLabel.font = KSystemFont(__I6Width(15));
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    __weak typeof(self) weak = self;
    [button addActionBlock:^(id sender) {
        if (self.tag == 0) {
            NSInteger count = self.rt_navigationController.rt_viewControllers.count;
            UIViewController *vc = self.rt_navigationController.rt_viewControllers[count - 4];
            weak.delegate = self.rt_navigationController.rt_viewControllers[count - 4];
            if ([weak.delegate respondsToSelector:@selector(getUIImageFromPhotoViewController:image:)]) {
                [weak.delegate getUIImageFromPhotoViewController:weak image:weak.image];
            }
            [weak.navigationController popToViewController:vc animated:YES];
        }else if(self.tag == 2){
            NSInteger count = self.rt_navigationController.rt_viewControllers.count;
            UIViewController *vc = self.rt_navigationController.rt_viewControllers[count - 3];
            weak.delegate = self.rt_navigationController.rt_viewControllers[count - 3];
            if ([weak.delegate respondsToSelector:@selector(getUIImageFromPhotoViewController:image:)]) {
                [weak.delegate getUIImageFromPhotoViewController:weak image:weak.image];
            }
            [weak.navigationController popToViewController:vc animated:YES];
        }else if(self.tag == 1){
            NSInteger count = self.rt_navigationController.rt_viewControllers.count;
            UIViewController *vc = self.rt_navigationController.rt_viewControllers[count - 3];
            weak.delegate = self.rt_navigationController.rt_viewControllers[count - 3];
            if ([weak.delegate respondsToSelector:@selector(getUIImageFromPhotoViewController:image:)]) {
                [weak.delegate getUIImageFromPhotoViewController:weak image:weak.image];
            }
            [weak.navigationController popToViewController:vc animated:YES];
        }
        
    
    } forControlEvents:UIControlEventTouchUpInside];
    CGSize size = self.image.size;
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.frame = CGRectMake((AppWidth - size.width*0.5)/2,__I6Height(20), size.width * 0.5, size.height * 0.5);
    imageView.image = self.image;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageView];

   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

